package org.cqut.system.work_record.controller;

import org.cqut.framework.web.response.ResultInfo;
import org.cqut.framework.web.response.Status;
import org.cqut.system.work_record.service.WorkRecordService;
import org.cqut.system.work_record.vo.StudentWorkRecordVo;
import org.cqut.system.work_record.vo.TeacherWorkRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author XiAoXu
 * @date 2021/11/13 17:10
 * @description
 */
@RestController
@RequestMapping("/workRecord")
public class WorkRecordController {
    @Autowired
    private WorkRecordService workRecordService;

    @RequestMapping(method = RequestMethod.POST)
    public ResultInfo saveRecord(@RequestBody Map<Object, Object> map) {
        boolean flag = workRecordService.saveRecords(map);
        if (flag) {
            return new ResultInfo(Status.SUCCESS.code, Status.SUCCESS.message);
        } else {
            return new ResultInfo(Status.WARN.code, Status.WARN.message);
        }
    }

    @RequestMapping(method = RequestMethod.GET, path = "/workListForTeacher/{courseId}")
    public ResultInfo queryRecordListForTeacher( @PathVariable("courseId") String courseId) {
        List<TeacherWorkRecordVo> recordVoList = workRecordService.getRecordListForTeacher(courseId);
        if (recordVoList != null) {
            return new ResultInfo(Status.QUERY_DETAILS_SUCCESS.code, Status.QUERY_DETAILS_SUCCESS.message, recordVoList);
        } else {
            return new ResultInfo(Status.QUERY_DETAILS_ERROR.code, Status.QUERY_DETAILS_ERROR.message);
        }
    }

    @RequestMapping(method = RequestMethod.GET, path = "/studentRecordList/{courseId}/{studentId}")
    public ResultInfo queryRecordListForStudent(@PathVariable("studentId") String studentId, @PathVariable("courseId") String courseId) {
        List<StudentWorkRecordVo> recordVoList = workRecordService.getRecordListForStudent(studentId, courseId);
        if (recordVoList != null) {
            return new ResultInfo(Status.QUERY_DETAILS_SUCCESS.code, Status.QUERY_DETAILS_SUCCESS.message, recordVoList);
        } else {
            return new ResultInfo(Status.QUERY_DETAILS_ERROR.code, Status.QUERY_DETAILS_ERROR.message);
        }
    }
}
